/* Copyright (C) 2010 Luca Piccinelli
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* 
 * File:   bridgeGenerator.h
 * Author: picci
 *
 * Created on November 20, 2010, 12:04 PM
 */

#ifndef BRIDGEGENERATOR_H
#define	BRIDGEGENERATOR_H

#include "prj_definitions.h"
#include "generators/generators.h"
#include "exceptions/generator_exceptions.h"

namespace NAMESPACE{

class BridgeGenerator : public AbstractGenerator{
public:
    using AbstractGenerator::generate;
    using AbstractGenerator::set_key;
private:
    virtual void free_element(IOElement* el);
    virtual memory_size_t measure_memory();

    const Generator* from_generator;
    size_t grab_instant; ///< This is the past instant in the history of from_generator, from which to extract the new input
public:
    ~BridgeGenerator();
    BridgeGenerator();
    BridgeGenerator(const BridgeGenerator& bg);
    BridgeGenerator& operator=(const BridgeGenerator& bg);

    BridgeGenerator(const Generator& from_gen, const IOKey& k, const size_t& _grab_instant = 0);

    virtual Generator& set_key(const std::string& ns, const std::string& key_name) throw(bad_generator);
    BridgeGenerator& set_from_generator(const Generator& from_gen);
    BridgeGenerator& set_grab_instant(const size_t& _grab_instant);

    IOElement* generate(const IOKey& key) throw(bad_generator);

    virtual bool operator==(const Generator& bg) const;
    virtual bool operator!=(const Generator& bg) const;
};

}

#endif	/* BRIDGEGENERATOR_H */

